using System;
using Slaks.DocumentSerialization.Dictionary;
using Slaks.DocumentSerialization.Document;

namespace Slaks.Graphs.GraphBuilder.SchenkerDictionary
{
	/// <summary>
	/// Summary description for RawFrequencyRepresentationSlaks.
	/// </summary>
	public class RawFrequencyDictionaryRepresentationSchenker : SchenkerDictionaryBuilder, IDictionaryRepresentation
	{
		#region IDictionaryRepresentation Members

		public Graph Build(Document document, DictionaryMap dictionaryMap)
		{
			string documentName = document.FileName;
			int index = documentName.LastIndexOfAny(new char[] {'\\', '/'});
			if (index >= 0 && (index + 1 < documentName.Length)) documentName = documentName.Substring(index + 1);

			Graph graph = new Graph(documentName);

			Vertex vertex;
			string sectionType;

			//iterate through nodes
			foreach (Node node in document.Nodes)
			{
				//check if the vertex is in the list of frequent nodes from dictionary
				if (dictionaryMap.Contains(node.Id) == false) continue;
				vertex = graph.CreateAddVertex(node.Id);
				vertex.Frequency = node.TotalTermFrequency;

				//iterate through sections
				foreach (Section section in node.Sections)
				{
					sectionType = section.GetSectionTypeString();
					Section.SectionType sectionTp = Section.GetSectionTypeByString(sectionType);
					//iterate through sentences
					foreach (Sentence sentence in section.Sentences)
					{
						AddRelations(document, graph, dictionaryMap, vertex, 1, 1, sentence, sectionTp, BuilderType.RawFrequencyDictionaryRepresentationSchenker);
					}
				}
			}


			return graph;
		}

		public Graph Build(Document document, int nParameter, DictionaryMap dictionaryMap)
		{
			throw new NotImplementedException("RawFrequencyDictionaryRepresentationSlaks does not implement this method");
		}

		#endregion
        protected override string GetBuilderName()
        {
            return "Schenker's Raw Frequency By Dictionary Representation";
        }
        protected override string GetBuilderDescription()
        {
            return "Labels the vertexes with the term's frequency in the document. Only the most frequent terms in the documents collection are used.";
        }
	}
}